package prolog.terms

abstract class Source extends Fluent {
  def getElement(): Term
  def stop(): Term

  def toList(toCopy: Boolean): Term = {
    var head = getElement()
    if (null == head)
      return Const.nil
    if (toCopy) head = head.copy
    val l = new Cons(head, Const.nil)
    var curr = l
    var more = true
    while (more) {
      head = getElement()
      if (null == head)
        more = false
      else {
        if (toCopy) head = head.copy
        val tail = new Cons(head, Const.nil)
        curr.args(1) = tail
        curr = tail;
      }
    }
    return l
  }
}